package com.ogawa.chair7808.ui.presenter;


/**
 * Created by FHB on 2018/2/1.
 */


import android.util.Log;

import com.easepal.socketiolib.model.SocketModel;
import com.ogawa.base.Constant.CommmandNum;
import com.ogawa.chair7808.manager.DataManager;
import com.ogawa.chair7808.observer.SocketDataObserver;
import com.ogawa.chair7808.ui.iview.IAdvancedMassageView7506;

import io.reactivex.disposables.Disposable;

/**
 * Created by fhb on 2018/2/1.
 */


public class AdvancedMassagePressenter7506 implements SocketDataObserver.SocketReceive{
    IAdvancedMassageView7506 mView;
    private boolean hasHandChange;
    private boolean hasKeandChange;
    private boolean flag;
    private boolean isToAuto;
    private Disposable mDisposable;

    public AdvancedMassagePressenter7506(IAdvancedMassageView7506 view) {
        mView = view;
        SocketDataObserver.getInst().registerObserver(this);
    }

    public void getTimes(){
        DataManager.getDataManager().sendCommond(CommmandNum.mStatusTIME);
//        CommondManager.getInst().getState(, new GetStateCallback() {
//            @Override
//            public void onGetStateSuccess(BaseResponse<BeanStateInfo> program) {
//                if(program.getData().getCmdRsps()!=null){
//
//                    DataManager.getInst().putKeyValue(program.getData().getCmdRsps().get(0).getKey(),(program.getData().getCmdRsps().get(0).getValue()));
//                    String value = (program.getData().getCmdRsps().get(0).getValue());
//                    String min =value.substring(0,value.indexOf(":"));
//                    String sec =value.substring(value.indexOf(":")+1);
//                    mView.getTime(min,DataManager.getInst().getValue(sec));
//
//                }
//                else {
//
//                }
//            }
//
//            @Override
//            public void onStateFailure() {
//
//            }
//        });
    }
    public void onDestory(){
        SocketDataObserver.getInst().removeObserver(this);
    }


    @Override
    public void onRceiveSocket(SocketModel model) {
        String key = model.getKey();
        String value = model.getValue();
        if(key.equals(CommmandNum.mStatusAuto)){
            if(!value.equals("0")){
                isToAuto = true;
                SocketDataObserver.getInst().removeObserver(this);
                runAuto(value);
            }
         }
        else if(key.equals(CommmandNum.mStatusRunning)){
            Log.e("isPause",value+"");
            mView.isPause(value.equals("3"));

        }

        else if(key.equals(CommmandNum.mStatusKnead)){
            if(!value.equals("0")){
               mView.handRunning();
            }
//            hasKeandChange =true;
        }
        else if(key.equals(CommmandNum.mStatusHand)){
            if(!value.equals("0")){
                mView.handRunning();
            }
//            hasHandChange = true;

        }
        else if(model.getKey().equals(CommmandNum.mStatusShoulderScanning)){
            if(value.equals("1")){
                mView.startToScan();
            }
        }
        else if(model.getKey().equals(CommmandNum.mStatusShoulderAdjust)){
            if(value.equals("1")){
                mView.startAdjust();
            }
        }


//            if(hasHandChange||hasKeandChange){
//            if(!flag){
//                //flag 用于标识以下方法时候在执行了  如果在执行了 就不用重复执行
//                flag =true;
//                massageChange();
//            }
//
//        }

    }

//    /**
//     * 手动程序改变  重新获取时间
//     */
//    public void massageChange(){
//        if(isToAuto){
//            hasHandChange =false;
//            hasKeandChange = false;
//            flag = false;
//        }else {
//            Observable.timer(200, TimeUnit.MILLISECONDS)
//                    .subscribeOn(Schedulers.io())
//                    .subscribe(new Observer<Long>() {
//                        @Override
//                        public void onSubscribe(@NonNull Disposable d) {
//
//                            mDisposable =d;
//                        }
//
//                        @Override
//                        public void onNext(@NonNull Long aLong) {
////                            getTimes();
//                            hasHandChange =false;
//                            hasKeandChange = false;
//                            flag = false;
//                            mDisposable.dispose();
//                        }
//
//                        @Override
//                        public void onError(@NonNull Throwable e) {
//                        }
//
//                        @Override
//                        public void onComplete() {
//                        }
//                    });
//        }
//
//    }
    /**
     * 执行了自动程序
     */
    private void runAuto(String value){
        String name ="";
        if(value.equals("1")){
            name = "全身舒展";
        }
        else if(value.equals("2")){
            name = "老年模式";
        }
        else if(value.equals("3")){
            name = "泰式拉伸";
        }
        else if(value.equals("4")){
            name = "速按放松";
        }
        else if(value.equals("5")){
            name = "清晨唤醒";
        }
        else if(value.equals("6")){
            name = "舒眠模式";
        } else if(value.equals("7")){
            name = "运动恢复";
        }
        else if(value.equals("8")){
            name = "深度放松";
        }
        else if(value.equals("9")){
            name = "上班族";
        }
        else if(value.equals("10")){
            name = "低头族";
        }
        else if(value.equals("11")){
            name = "开车族";
        }
        else if(value.equals("12")){
            name = "高跟族";
        } else if(value.equals("13")){
            name = "午间小休";
        }
        else if(value.equals("14")){
            name = "女王美体";
        }
        else if(value.equals("15")){
            name = "男士健体";
        }
        else if(value.equals("16")){
            name = "久坐释压";
        }
        mView.toAutoActivity(name);

    }
}

